<template>
  <div>
    <el-row :gutter="10" style="margin-bottom: 20px">
      <el-col v-for="(item, index) in pagingList" :key="index" :span="6">
        <div class="item ellipsis" :title="item.name" :style="{ backgroundColor: colorLib[roleKey ? item.roleResult[roleKey] || 0 : item.status] }" @click="cellClick(item)">
          <span class="name">{{ item.name }}</span>
          <div class="batch">第 {{ item.batch }} 批</div>
        </div>
      </el-col>
    </el-row>
    <el-pagination background layout="prev, pager, next" :total="filteredList.length" :page-size.sync="pageSize" :current-page.sync="pageNum" />
  </div>
</template>
<script>
// 桩基
import { recordMixin } from './mixin'
export default {
  name: 'Piles',
  mixins: [recordMixin],
  data() {
    return {
      pageNum: 1,
      pageSize: 40
    }
  },
  computed: {
    filteredList() {
      const { list, status, roleKey } = this
      if (status === undefined) return list
      return list.filter(item => status === (roleKey ? item.roleResult[roleKey] || 0 : item.status))
    },
    pagingList() {
      // 本地分页
      const { pageNum, pageSize } = this
      const offset = Math.max(0, pageNum - 1) * pageSize
      return this.filteredList.slice(offset, offset + pageSize)
    }
  },
  watch: {
    roleKey() {
      this.pageNum = 1
    },
    status() {
      this.pageNum = 1
    }
  }
}
</script>
<style lang="scss" scoped>
.item {
  position: relative;
  height: 45px;
  font-size: 14px;
  color: white;
  padding: 8px 5px 0;
  border: 1px solid transparent;
  border-radius: 2px;
  text-align: center;
  margin-bottom: 10px;
  cursor: pointer;
  &:hover {
    border-color: #1ab394;
  }
}
.batch {
  position: absolute;
  left: 5px;
  bottom: 2px;
  font-size: 12px;
  line-height: 12px;
}
</style>
